<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
</head>
<body>

<input type = "text" placeholder = "输入用户名"  id = "user_id">
<input type = "text" placeholder = "输入密码"    id = "user_password"  >

<button id = "btn" onclick = "login()">登录</button>


<script>
    function login(){
        const user_id = document .getElementById ("user_id").value
        const user_password  = document .getElementById ("user_password").value

        if (!user_id||!user_password){
            alert("请输入用户名或密码")
            return
        }
       fetch('/login',
           {
               method:"post",
               headers:{
                   "Content-Type":"application/json;charset=UTF-8"
               },
               body:JSON.stringify ({user_id:user_id,user_password:user_password})
           }).then(res =>res.json()).then(res => {

               console.log(res)
               if(res.user_identity) {
                   alert("登录成功")
                   location.href = '/'
               }
               else{
                   alert("账号或密码有误")
               }

       })
    }
</script>


</body>



</html>